package com.zh.analysis.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zh.analysis.service.GpsService;
import com.zh.common.utils.RedisUtil;
import com.zh.device.po.DevcieExample;
import com.zh.push.util.WebSocketPush;
import org.springframework.stereotype.Service;

@Service
public class GpsServiceImpl implements GpsService {

    /**
     * GPS 数据解析
     *
     * @param jsonObject
     * @return
     */

    public void gps(JSONObject jsonObject) {

        String deviceSn = jsonObject.getString("Serial");
        if (!RedisUtil.hasKey(deviceSn)) return;
            //todo
        //获取gps数据
        DevcieExample gps = (DevcieExample) RedisUtil.get(deviceSn);

        JSONObject resJson = this.prssonGps(jsonObject);

        resJson.put("name", gps.getBehaviorDO().getFamilyUserName());

        //推送gps
        WebSocketPush.gspPush(resJson, gps.getDeviceRelas());
    }

    /**
     * 解析gps数据
     * @param jsonObject
     * @return
     */
    private JSONObject prssonGps(JSONObject jsonObject) {
        JSONObject resJson = jsonObject.getJSONObject("Detail");
        JSONObject res = new JSONObject();

        //维度
        res.put("lt", resJson.getString("Longitude"));
        //经度
        res.put("la", resJson.getString("Latitude"));

        return res;

    }

}
